import md5
from sqlalchemy import Column, Unicode
from sqlalchemy.ext.declarative import declarative_base
 
Base = declarative_base()
 

class User(Base):
    """ holding class for the User object""" 
    __tablename__ = "users"
 
    username = Column(Unicode, primary_key=True)
    email = Column(Unicode)
    password = Column(Unicode)
    country = Column(Unicode)
 
    def __init__(self, username, email, password, country):
        self.username = username
        self.email = email
        self.password = password
        self.country = country
 
    def __repr__(self):
        return "<User('%s','%s', '%s', '%s')>" % (self.username, self.email, self.password, self.country)
        
    def validate_password(self, password):
        m = md5.new()
        m.update(password)
        password = m.hexdigest()      
        if self.password == password:
            return True
        return False     	        
